﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Private odid As String
	Private ulv As UltimateListView
	Private curTec As Teacher
	Private m As Map
	Type shiduan(status As String,money As String,date As String,id As String,starttime As String,endtime As String)
	Private lstshiduan As List
	Private bCanRefundAll As Boolean
	Private nLastShiduanIdx As Int
	Private bottel As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("layorderdetail")
	odid=g_store.get("odid")
	Log(odid)
	initviews
End Sub
Sub initviews
	Dim nH1 As Int=90dip
	Dim nH2 As Int=60dip
	ulv.AddLayout("itemorderheader","ui_LayoutCreator","header_ContentFiller",nH1,False)
	ulv.Addlayout("itemordercommon","ui_LayoutCreator","data_ContentFiller",nH2,False)
	ulv.Addlayout("itemordertxt","ui_LayoutCreator","data_ContentFiller",nH2,False)
	Dim cd As ColorDrawable
	cd.Initialize(0xFFEFEFEF,0)
	ulv.DividerDrawable=cd
	ulv.DividerHeight=1dip
	reqOrderDetail(odid)
End Sub
Sub reqOrderDetail(oid As String)
	comm.showProgress("正在获取订单详情")
	ParseHelper.doGetReq(Me,"reqorddetail",comm.getApi(comm.apiIdx.REQORDDETAIL),Array As String("order_sn",oid))
End Sub
Sub parseOrderDetail(str As String)
	Dim parser As JSONParser 
	parser.Initialize(str) 
	m.Initialize
	Dim root As Map = parser.NextObject 
	Dim data As Map = root.Get("data") 
	Dim seller_kechen_id As String = data.Get("seller_kechen_id") 
'	Dim Logs As List = data.Get("log") 
'	For Each collog As Map In Logs
'	    Dim log_id As String = collog.Get("log_id") 
'	    Dim money As String = collog.Get("money") 
'	    Dim remark As String = collog.Get("remark") 
'	    Dim order_type As String = collog.Get("order_type") 
'	    Dim order_sn As String = collog.Get("order_sn") 
'	    Dim operator As String = collog.Get("operator") 
'	    Dim log_time As String = collog.Get("log_time") 
'	    Dim zi_order_sn As String = collog.Get("zi_order_sn") 
'	Next 
	Dim buyer_name As String = data.Get("buyer_name") 
	Dim order_money As String = data.Get("order_money") 
	Dim keshi As String = data.Get("keshi") 
	m.put("keshi",keshi)
	Dim remark As String = data.Get("remark") 
	Dim seller_mobile As String = data.Get("seller_mobile") 
	If seller_mobile.Trim.Length>1 Then
		bottel.Tag=seller_mobile.Trim
	Else
		bottel.Tag=""
	End If
	Dim usertel As String = data.Get("usertel") 
	Dim buyer_id As String = data.Get("buyer_id") 
	Dim kechen_type As String = data.Get("kechen_type") 
	Dim into_money As String = data.Get("into_money") 
	Dim shiduan_list As List = data.Get("shiduan_list") 
	
	Dim buyer_mobile As String = data.Get("buyer_mobile") 
	Dim seller_name As String = data.Get("seller_name") 
	Dim order_type As String = data.Get("order_type") 
	Dim seller_id As String = data.Get("seller_id") 
	Dim image As String = data.Get("image") 
	Dim finished_time As String = data.Get("finished_time") 
	Dim is_app As String = data.Get("is_app") 
	Dim kechen_mode As String = data.Get("kechen_mode") 
	Dim fukuan_type As String = data.Get("fukuan_type") 
	Dim banner_id As String = data.Get("banner_id") 
	Dim pay_time As String = data.Get("pay_time") 
	Dim sk_address As String = data.Get("sk_address") 
	Dim yhj_id As String = data.Get("yhj_id") 
	Dim kc_title As String = data.Get("kc_title") 
	Dim quan_money As String = data.Get("quan_money") 
	Dim order_id As String = data.Get("order_id") 
	Dim add_time As String = data.Get("add_time") 
	Dim order_sn As String = data.Get("order_sn") 
	Dim status As String = data.Get("status") 
	m.Put("status",status)
	Dim username As String = data.Get("username") 
	m.Put("headimg",comm.combinPic( image))
	m.Put("seller_name",seller_name)
	m.Put("order_sn",order_sn)
	m.Put("add_time",add_time)
	m.Put("kc_title",kc_title)
	m.Put("order_money",order_money)
	ulv.AddItem("itemorderheader",0)
	ulv.BulkAddItems(6,"itemordercommon",1)	
	lstshiduan.Initialize
	bCanRefundAll=True
	If status.EqualsIgnoreCase("退款中") Then bCanRefundAll=False
	For Each colshiduan_list As Map In shiduan_list 
	    Dim sd_start_time As String = colshiduan_list.Get("sd_start_time") 
	    Dim finished_time As String = colshiduan_list.Get("finished_time") 
	    Dim tuikuan_time As String = colshiduan_list.Get("tuikuan_time") 
	    Dim sd_mode As String = colshiduan_list.Get("sd_mode") 
	    Dim sd_hour As String = colshiduan_list.Get("sd_hour") 
	    Dim trd_id As String = colshiduan_list.Get("trd_id") 
	    Dim sd_money As String = colshiduan_list.Get("sd_money") 
	    Dim sd_end_time As String = colshiduan_list.Get("sd_end_time") 
	    Dim riqi As String = colshiduan_list.Get("riqi") 
	    Dim id As String = colshiduan_list.Get("id") 
	    Dim add_time As String = colshiduan_list.Get("add_time") 
	    Dim order_sn As String = colshiduan_list.Get("order_sn") 
	    Dim status As String = colshiduan_list.Get("status") 
		Dim sdi As shiduan
		sdi.Initialize
		sdi.id=trd_id
		sdi.date=riqi
		sdi.starttime=sd_start_time
		sdi.endtime=sd_end_time
		sdi.status=status
		sdi.money=sd_money
		lstshiduan.Add(sdi)
		If status.EqualsIgnoreCase("已排课")=False Then bCanRefundAll=False
	Next 
	ulv.AddItem("itemordertxt",-2)
	If lstshiduan.Size=0 Then
		ulv.AddItem("itemordertxt",-1)
	Else
		ulv.BulkAddItems(lstshiduan.Size,"itemordertxt",0)
	End If
	
	
End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		Dim str As String=thj.GetString
		Dim nr As netRes=ParseHelper.getStatusData(str)
		If nr.nCode=200 Then
			Select thj.JobName
			Case "reqorddetail"
				parseOrderDetail(str)
			Case "reqrefundall"
				comm.TL("申请退款成功，请等待客服处理")
				Activity.Finish
			Case "reqrefundcid"
				comm.TL("申请退款成功，请等待客服处理")
				Dim sd As shiduan=lstshiduan.Get(nLastShiduanIdx)
				sd.status="处理中"
				lstshiduan.Set(nLastShiduanIdx,sd)
				ulv.RefreshContent
			End Select
			
		Else
			comm.TL("错误:"&nr.sData)
		End If
	Else
		comm.TL("网络错误:"&thj.ErrorMessage)
	End If
	thj.Release
End Sub
Sub ui_LayoutCreator(LayoutName As String, LayoutPanel As Panel)
	LayoutPanel.LoadLayout(LayoutName)
End Sub
Sub data_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Select LayoutName.ToLowerCase
	Case "itemordertxt"
		Dim k As Label=LayoutPanel.GetView(0)
		If ItemID=-1 Then
			k.Text="暂未排课"
		Else if ItemID=-2 Then
			k.Text=$"总课时:${m.GetDefault("keshi",0)}小时"$
		Else
			Dim sd As shiduan=lstshiduan.Get(ItemID)
			k.Text=sd.date&" "&sd.starttime&" "&sd.endtime&" "&sd.status
			Dim v As Label=LayoutPanel.GetView(1)
			If sd.status.EqualsIgnoreCase("已排课") Then
				v.Visible=True
			Else
				v.Visible=False
			End If
			v.Tag=ItemID
		End If
		
	Case "itemordercommon"
		Dim k,v As Label
		k=LayoutPanel.GetView(0)
		v=LayoutPanel.GetView(1)
		v.TextColor=Colors.Black
		Select Position
		Case 1
			k.Text="订单编号:"
			v.Text=m.GetDefault("order_sn","")
		Case 2
			k.Text="订单时间:"
			v.Text=m.GetDefault("add_time","")
		Case 3
			k.Text="订单类型:"
			v.Text=m.GetDefault("kc_title","")
		Case 4
			k.Text="订单金额:"
			comm.setFA(v,"fa-rmb",m.GetDefault("order_money","0"))
			v.Textcolor=comm.N_COLOR_ORANGE
		Case 5
			k.Text="优惠金额:"
			comm.setFA(v,"fa-rmb",m.GetDefault("quan_money","0"))
			v.Textcolor=comm.N_COLOR_ORANGE
		Case 6
			'实际
			k.Text="实付金额:"
			Try
				comm.setFA(v,"fa-rmb",m.GetDefault("order_money","0")-m.GetDefault("quan_money","0"))
			Catch
				'Log(LastException)
				comm.setFA(v,"fa-rmb","0")
			End Try
			'comm.setFA(v,"fa-rmb",m.GetDefault("order_money","0")-m.GetDefault("quan_money","0"))
			v.Textcolor=comm.N_COLOR_ORANGE
		
		End Select
	End Select
	
End Sub
Sub header_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim p As Panel=	LayoutPanel.GetView(0)
	Dim riv As RIV=p.GetView(0)
	comm.loadimg(m.GetDefault("headimg",""),riv)
	Dim teachername As Label=LayoutPanel.GetView(1)
	teachername.Text=m.GetDefault("seller_name","")
	Dim label2 As Label=LayoutPanel.GetView(2)
	label2.Text=m.GetDefault("kc_title","")
	Dim label3 As Label=LayoutPanel.GetView(3)
	label3.Text=m.GetDefault("status","")
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
	ulv.StopAsyncLoading
	ulv.StopScrolling
End Sub


Sub ivback_Click
	Activity.Finish
End Sub

Sub botlx_Click
	
End Sub

Sub bottel_Click
	Dim s As View=Sender
	comm.calltel(s.Tag)
End Sub

Sub botkf_Click
	
End Sub
Sub showdialog As String
	Dim pbody As Panel
	Dim bd As BetterDialogs
	pbody=comm.CreateCustomPanel(Activity,80%x,45%y)
	pbody.LoadLayout("dlgrefundres")
	Dim dlgParams As BD_CustomDlgParams
	Dim edt As EditText=pbody.GetView(0)
	dlgParams.Initialize
	dlgParams.DialogBody = pbody
	dlgParams.BodyWidth = pbody.Width
	dlgParams.BodyHeight = 180dip
	dlgParams.PositiveButton="确定"
	dlgParams.NegativeButton="取消"
	'dlgParams.Duration = 30 '自动关闭
	Dim DR As Int = bd.CustomDialog(dlgParams, "CD1")
	If DR==DialogResponse.POSITIVE Then
'		lstData.Add((lstData.Size+1)&"")
'		ulv.AddItem("itemyhq",lstData.Size)
		Return edt.Text.Trim
	End If
End Sub
Sub reqrefundall(mid As String,cid As String)
	Dim res As String=showdialog
	Dim jobname As String="reqrefundall"
	If cid.Length>1 Then
		'子订单退款
		jobname="reqrefundcid"
	End If
	If res.Length>0 Then
		comm.showProgress("正在提交退款请求")
		ParseHelper.doPostReqArr(Me,jobname,comm.getApi(comm.apiIdx.REQORDERREFUND),Array As String("order_sn",odid,"zi_order_sn",cid,"tk_content",res),"")
	Else
		comm.TL("退款原因不能为空！")
	End If
End Sub
Sub bottk_Click
	If bCanRefundAll Then
		reqrefundall(odid,"0")
	Else
		Msgbox("当前订单状态不能退款，如果已排课请尝试具体课程的退款。","提示")
	End If
	
End Sub
Sub lbltk_Click
	Dim v As View=Sender
	nLastShiduanIdx=v.Tag
	Dim ks As shiduan=lstshiduan.Get(nLastShiduanIdx)
	reqrefundall(odid,ks.id)
End Sub